﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ultima;
using Expand;

namespace SpellCaster3.Forms.Controls
{
    public class HueControlButton : HueControl, IInputOutput
    {
        public HueControlButton(int hueIndex)
            : base(hueIndex)
        {
            Value = hueIndex;
            Click += new EventHandler(HueControlButton_Click);
        }

        private void HueControlButton_Click(object sender, EventArgs e)
        {
            using (HuePicker dlg = new HuePicker(Value))
                if (dlg.ShowDialog(this) == DialogResult.OK)
                    Value = dlg.Value;
        }

        public HueControlButton() : this(1) { }

        private int _LastValue = 1;
        private int _Value = 1;

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false)]
        [Bindable(true)]
        public int Value
        {
            get { return _Value; }
            set
            {
                _LastValue = Value;
                _Value = value;
                HueIndex = Value;
                OnValueChanged(this, EventArgs.Empty);
                OnIOValueChanged(this, new LastValueEventArgs<object>(_LastValue));
            }
        }

        private void OnValueChanged(object sender, EventArgs e)
        {
            if (ValueChanged != null) ValueChanged(sender, e);
        }

        private void OnIOValueChanged(object sender, LastValueEventArgs<object> e)
        {
            if (IOValueChanged != null) IOValueChanged(sender, e);
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Browsable(false)]
        public object IOValue
        {
            get { return (object)Value; }
            set
            {
                Value = (int)value;
            }
        }

        public event EventHandler ValueChanged;

        public event EventHandler<LastValueEventArgs<object>> IOValueChanged;
    }
}
